package com.qf.java2201.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import com.qf.java2201.common.PageVo;
import com.qf.java2201.common.R;
import com.qf.java2201.mapper.ShopCarMapper;
import com.qf.java2201.pojo.ShopCar;

import com.qf.java2201.service.ShopCarService;
import com.qf.java2201.vo.PieVo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;
import java.util.Map;


@Service("shopCarService")
public class ShopCarServiceImpl implements ShopCarService {

    @Autowired
    private ShopCarMapper shopCarMapper;
    @Override
    public PageVo<ShopCar> getPageData(Map<String, Object> params) {
        String page = (String) params.get("page");
        String limit = (String) params.get("limit");
        //mybatis
        PageHelper.startPage(Integer.parseInt(page),Integer.parseInt(limit));

        List<ShopCar> shopCars = shopCarMapper.selectByParams(params);

        //List<ShopCar> shopCars = ShopCartMapper.selectByParams(params);

        PageInfo<ShopCar> shopCarPageInfo = new PageInfo<>(shopCars);

        // 把分页数据 封装到 PageVo      这个 PageVo  符合 layui 的  列表数据格式
        PageVo<ShopCar> shopCarPageVo = new PageVo<>();
        shopCarPageVo.setData(shopCarPageInfo.getList());
        shopCarPageVo.setCode(0);
        shopCarPageVo.setCount(shopCarPageInfo.getTotal());
        shopCarPageVo.setMsg("购物车列表数据");
        return shopCarPageVo;
    }

    @Override
    public int addShopCar(ShopCar shopCar) {
        return shopCarMapper.addShopCar(shopCar);
    }

    @Override
    public int deleteShopCar(Integer cartid) {
        return shopCarMapper.deleteShopCar(cartid);
    }

    @Override
    public int updateShopCar(ShopCar shopCar) {
        return shopCarMapper.updateShopCar(shopCar);
    }

    @Override
    public List<PieVo> sexPieData() {
        return shopCarMapper.sexPieData();
    }


}
